package com.layfuture.lftserver.order;

import com.layfuture.lftserver.order.spi.OrderCompleted;
import com.layfuture.lftserver.order.spi.OrderDto;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class OrderManagement {
    private final ApplicationEventPublisher events;
    @Transactional
    public void complete(OrderDto orderDto) {

        // State transition on the order aggregate go here

        // Invoke related functionality
        events.publishEvent(new OrderCompleted(orderDto.getId()));
    }
}
